package com.ruoyi.info.service.impl;

import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.info.mapper.EnterpriseBaseMapper;
import com.ruoyi.info.mapper.ProductMapper;
import com.ruoyi.info.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 门户网站使用的业务
 */
@Service
public class HomeServiceImpl implements HomeService {

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private EnterpriseBaseMapper enterpriseBaseMapper;

    @Autowired
    private RedisCache redisCache;
    @Override
    public Map<String, Integer> basicInfo() {
        HashMap<String, Integer> basicInfo;
//        basicInfo = (HashMap<String, Integer>) redisCache.<Integer>getCacheMap("basicInfo");
//        if(!basicInfo.isEmpty()){
//            return basicInfo;
//        }
        basicInfo = new HashMap<>();
//        产品数量
        int count = productMapper.selectCurrentCount();
        basicInfo.put("count",count);
//        厂商数量
        int manufacturerCount = productMapper.selectManufacturerCount();
        basicInfo.put("manufacturerCount",manufacturerCount);
//        查询覆盖行业数量
        int industryCount = productMapper.selectIndustryCount();
        basicInfo.put("industryCount",industryCount);
//        近N个月新增产品
        int addMonthCount = productMapper.selectAddCount(3);
        basicInfo.put("addMonthCount",addMonthCount);
//      覆盖省级行政区域
        int provinceRegionCount = enterpriseBaseMapper.selectProvinceRegionCount();
        basicInfo.put("provinceRegionCount",provinceRegionCount);
//      覆盖市级行政区域
        int cityRegionCount = enterpriseBaseMapper.selectCityRegionCount();
        basicInfo.put("cityRegionCount",cityRegionCount);
//        redisCache.<Integer>setCacheMap("basicInfo",basicInfo);
//        redisCache.expire("basicInfo",60*60*24);
        return basicInfo;
    }

    /**
     * 行业分布
     * @return
     */
    public List<Map<String,Object>> industryDistribution(){
       return  productMapper.selectIndustryDistribution();
    }
    /**
     * 行业分布
     * @return
     */
    public List<Map<String,Object>> regionDistributio(){
       return  enterpriseBaseMapper.selectRegionDistribution();
    }


    public List<Map<String,Object>> regionCodeDistribution(){
        return enterpriseBaseMapper.selectRegionCodeDistribution();
    }
}
